<template>
  <div class="page flex-column">
    <div class="course-result flex-column">
      <div class="result-title">我的课程</div>
      <a-flex v-if="isNotEmpty(storeMyCourse.courseSource)" wrap="wrap" gap="20" class="result-list">
        <course-card v-for="item in storeMyCourse.courseSource" :key="item.courseId"
          :courseId="item.srcCourseId"
          :courseTitle="item.name"
          :courseImg="item.pic"
          :courseProgress="item.progress">
        </course-card>
      </a-flex>
      <div v-else class="empty-list">
        <div class="empty-box">
          <img src="@/assets/images/empty-course.png" />
          <div class="empty-tip">
            <div class="empty-label">还没有开始学习的课程，</div>
            <div class="empty-btn">
              <text-button label="去看看" color="#E8423A" size="16" @click="navigateTo('/selected-content/courses')">
                <template #right>
                  <CaretRightOutlined />
                </template>
              </text-button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div v-if="totalRecords>pageSize" class="course-pagination flex-row flex-center">
      <a-pagination 
        v-model:current="currentPage"
        v-model:pageSize="pageSize"
        :total="totalRecords"
        @change="storeMyCourse.handlePageChange"
        show-less-items />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onBeforeMount } from 'vue';
import { CaretRightOutlined } from '@ant-design/icons-vue';
import { isNotEmpty } from "@/utils";
import { useNavigation } from "@utils/navigation";
import useMyCourseStore from '@/stores/my-course';
import CourseCard from '@components/CourseCard.vue';
import TextButton from '@components/TextButton.vue';
import { miscApi } from "@/services";
 
const { navigateTo } = useNavigation();

const storeMyCourse = useMyCourseStore();
const currentPage = ref(storeMyCourse.pageNum);
const pageSize = ref(storeMyCourse.pageSize);
const totalRecords = ref(0);

onBeforeMount(async () => {
  await storeMyCourse.initData();

  totalRecords.value = storeMyCourse.totalRecords;

  await miscApi.traceViewPage("/my-course/list");
});
</script>

<style lang="less" scoped>
.page {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: @white-bg;

  .page-title {
    height: 22px;
    line-height: 22px;
    font-size: 20px;
    font-weight: 400;
    color: @font-grey-light;
    padding: 20px 30px;
  }

  .course-result {
    background-color: @white;
    border-radius: 20px;
    margin: 20px 30px;

    .result-title {
      height: 24px;
      line-height: 24px;
      font-size: 20px;
      font-weight: 500;
      color: @font-black;
      padding: 20px;
    }

    .result-list {
      margin: 25px;

      :deep(.course-card) {
        width: calc(25% - 15px);
        height: 282px;
        padding: 10px;

        .pic {
          height: 200px;
        }

        .name {
          height: 56px;
          line-height: 22px;
          font-size: 16px;
          font-weight: 500;
          color: @font-black;
        }
      }
    }

    .empty-list {
      height: 940px;
      display: flex;
      flex-direction: column;
      align-items: center;

      .empty-box {
        width: 510px;
        height: 309px;
        margin-top: 120px;
        position: relative;
        display: flex;
        justify-content: center;

        img {
          width: 100%;
          height: 100%;
        }

        .empty-tip {
          position: absolute;
          bottom: 0px;
          height: 16px;
          line-height: 16px;
          font-size: 16px;
          font-weight: 400;
          display: flex;
          flex-direction: row;
          align-items: center;

          .empty-label {
            color: @font-grey;
          }

          .empty-btn {
            color: @text-link-color;
          }
        }
      }
    }
  }
  .course-pagination {
    width: 100%;
    padding: 30px 30px 50px 30px;
  }
}



:deep(.ant-pagination) {
  .ant-pagination-item {
    min-width: 44px;
    height: 44px;
    margin-inline-end: 10px;
    line-height: 44px;
    background-color: @white;
    border: 1px solid @border-red-light;
    border-radius: 50%;

    a {
      font-size: 14px;
      font-weight: 400;
    }

    &.ant-pagination-item-active {
      border: 1px solid #ED171F;
    }
  }
  .ant-pagination-prev, .ant-pagination-next, .ant-pagination-jump-prev, .ant-pagination-jump-next {
    min-width: 44px;
    height: 44px;
    color: @font-black;
    line-height: 44px;
    border: 1px solid @border-red-light;
    border-radius: 50%;
    margin-inline-end: 10px;

    a {
      font-size: 14px;
      font-weight: 400;
      border-radius: 50%;
    }
  }

  .ant-pagination-prev:hover .ant-pagination-item-link, .ant-pagination-next:hover .ant-pagination-item-link {
    background-color: rgba(0, 0, 0, 0.06);
  }

  .ant-pagination-prev .ant-pagination-item-link, .ant-pagination-next .ant-pagination-item-link {
    border-radius: 50%;
  }

  .ant-pagination-options {
    display: none;
  }
}
</style>
